package org.mysfit.ctp4j.infra.utils;

import org.mysfit.ctp4j.api.vo.QuoteVO;
import org.mysfit.ctp4j.api.vo.ReqVO;
import org.mysfit.ctp4j.api.vo.TradeVO;

import ctp.thosttraderapi.CThostFtdcQuoteField;
import ctp.thosttraderapi.CThostFtdcTradeField;

/**
 * 操作系统信息判断工具类
 * 
 * @author long.gf
 *
 */
public class TradeConvertUtils {
	
	
	public static QuoteVO initQuote(ReqVO  t) {
		QuoteVO q = new QuoteVO();
		q.setRequestId(t.getRequestId());
		q.setFid(t.getFid());
		q.setFtime(t.getFtime());
		q.setFp(t.getFp());
		q.setQuoteId(t.getQuoteId());
		q.setRefQuoteId(t.getRefQuoteId());
		q.setQty(t.getQty());
		q.setCost(t.getCost());
		q.setKpFlag(t.getKpFlag());
		q.setDirection(t.getDirection());
		q.setPloyNo(t.getPloyNo());
		return q;
	}
	
	public static TradeVO initTrade(QuoteVO  q) {
		TradeVO t = new TradeVO();
		t.setRequestId(q.getRequestId());
		t.setFid(q.getFid());
		t.setFtime(q.getFtime());
		t.setFp(q.getFp());
		t.setQuoteId(q.getQuoteId());
		t.setRefQuoteId(q.getRefQuoteId());
		t.setQty(q.getQty());
		t.setCost(q.getCost());
		t.setKpFlag(q.getKpFlag());
		t.setDirection(q.getDirection());
		t.setPloyNo(q.getPloyNo());
		return t;
	}
	
	public static ReqVO initQuoteReqVO(QuoteVO  q) {
		ReqVO t = new ReqVO();
		t.setRequestId(q.getRequestId());
		t.setFid(q.getFid());
		t.setFtime(q.getFtime());
		t.setFp(q.getFp());
		t.setQuoteId(q.getQuoteId());
		t.setRefQuoteId(q.getRefQuoteId());
		t.setQty(q.getQty());
		t.setCost(q.getCost());
		t.setKpFlag(q.getKpFlag());
		t.setDirection(q.getDirection());
		t.setPloyNo(q.getPloyNo());
		return t;
	}
	
	public static ReqVO initTradeReqVO(TradeVO  q) {
		ReqVO t = new ReqVO();
		t.setRequestId(q.getRequestId());
		t.setFid(q.getFid());
		t.setFtime(q.getFtime());
		t.setFp(q.getFp());
		t.setQuoteId(q.getQuoteId());
		t.setRefQuoteId(q.getRefQuoteId());
		t.setQty(q.getQty());
		t.setCost(q.getCost());
		t.setKpFlag(q.getKpFlag());
		t.setDirection(q.getDirection());
		t.setPloyNo(q.getPloyNo());
		return t;
	}
	 
	
	public static QuoteVO convertQuoteRtn(CThostFtdcQuoteField c) {
		int requestId = c.getRequestID();
		ReqVO  t  =  TradeUtils.REQUEST_MAP.get(requestId);
		QuoteVO q = initQuote(t);
		q.setQuoteId(c.getQuoteSysID());
		q.setRefQuoteId(c.getQuoteRef());
		return q;
	}
	
	public static TradeVO convertTradeRtn(CThostFtdcTradeField c) {
		String fid = c.getInstrumentID();
		String quoteId = c.getOrderSysID();
		QuoteVO q = TradeUtils.QUOTE_MAP.get(fid).get(quoteId);
		TradeVO t = initTrade(q);
		t.setQty(c.getVolume());
		t.setCost(c.getPrice());
		t.setTradeId(c.getTradeID());
		return t;
	}
	
	
}
